package com.ruiyian.netty.scheduledtask;

// netty定时任务，用于动态更新设备数据
import com.aliyun.outboundbot20191226.models.DescribeJobResponseBody;
import com.ruiyian.common.constant.*;
import com.ruiyian.common.core.redis.RedisCache;
import com.ruiyian.common.utils.jfinsUtil.FinsMessage;
import com.ruiyian.common.utils.jfinsUtil.FinsMessageUtils;
import com.ruiyian.netty.DataUtils.DataUtils;
import com.ruiyian.netty.DataUtils.OutboundUtils;
import com.ruiyian.netty.nettyclient.NettyStarter;
import com.ruiyian.netty.nettyserver.MyChannelHandlerPool;
import com.ruiyian.system.domain.ServerEq;
import com.ruiyian.system.domain.ServerPointFormal;
import com.ruiyian.system.domain.vo.ServerEqFormal;
import com.ruiyian.system.service.ServerPointService;
import com.ruiyian.system.service.ServerService;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture;
import io.netty.channel.group.ChannelGroup;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.ruiyian.common.utils.*;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Slf4j
@Component
@EnableScheduling //开启定时任务
public class NettyScheduleTask {
    private int slectnum = 0;
    private List<ServerEqFormal> allServerList;
    @Autowired
    private ServerService serverService;

    @Autowired
    private ServerPointService serverPointService;

    @Autowired
    private RedisCache redisCache;

    @Autowired
    private OutboundUtils outboundUtils;


    private final static Logger logger = LoggerFactory.getLogger(NettyScheduleTask.class);

    private int fire_box_num = 0;
    private int secondry_control_num_24 = 0;
    private int secondry_control_num_25 = 0;
    private int visual_induction_num_24 = 0;
    private int visual_induction_num_25 = 0;
    private int light_control_num_24 = 0;
    private int traffic_control_num_24 = 0;
    private int fan_control_num_24 = 0;

    // 每天定时初始化消防箱标志位任务，每天早上8点30初始化一次
    @Scheduled(cron = "0 30 8 ? * *") //定时任务注解+cron表达式
    public void alarmInit(){
        // 复用点位表，获取消防箱寄存器地址
        List<ServerPointFormal> serverPointFormalList= serverPointService.getserverpoint(5);
        for(ServerPointFormal serverPointFormal:serverPointFormalList){
            serverPointFormal.setAlarm_flag("0");
            serverPointFormal.setAlarm_num(0);
            serverPointFormal.setJob_id("0");
            serverPointService.updateServerPoint(serverPointFormal);
        }
        logger.info("报警标志位初始化完成");
    }

    @Scheduled(cron = "0/15 * * * * ?") //定时任务注解+cron表达式
    public void testScheduleTask() throws Exception {
        // 返回消息
        JSONObject jsonReturn = new JSONObject();
        // 复用点位表，获取消防箱寄存器地址
        List<ServerPointFormal> serverPointFormalList= serverPointService.getserverpoint(5);
//        serverPointFormalList.get(0).setAlarm_flag("1");
//        Map<String,String> deviceInfoi = new HashMap<>();
//        deviceInfoi.put("tunnelName", "测试");
//        deviceInfoi.put("clientId", "5分控");
//        int y = outboundUtils.alarmPushByConditions("对面山隧道", "5分控2终端", deviceInfoi, serverPointFormalList.get(0));
        // 查出对面山隧道点位
        List<ServerPointFormal> secondryControlPointList_24= serverPointService.getserverpoint(1);
        // 查出黄陀尖隧道点位
        List<ServerPointFormal> secondryControlPointList_25= serverPointService.getserverpoint(2);
        // 查出对面山隧道视觉诱导点位
        List<ServerPointFormal> visualInductionPointList_24= serverPointService.getserverpoint(3);
        // 查出黄陀尖隧道视觉诱导点
        List<ServerPointFormal> visualInductionPointList_25= serverPointService.getserverpoint(4);
        // 查出对面山照明控制点位
        List<ServerPointFormal> lightControlPointList_24= serverPointService.getserverpoint(18);
        // 查出对面山交通控制点位
        List<ServerPointFormal> trafficControlPointList_24= serverPointService.getserverpoint(19);
        // 查出对面山通风控制点位
        List<ServerPointFormal> fanControlPointList_24= serverPointService.getserverpoint(20);
        System.out.println("执行定时任务" + LocalDateTime.now());
        // 置零判断，放到前面来
        if(fire_box_num>=serverPointFormalList.size()){
            fire_box_num = 0;
        }
        if(secondry_control_num_24>=secondryControlPointList_24.size()){
            secondry_control_num_24 = 0;
        }
        if(secondry_control_num_25>=secondryControlPointList_25.size()){
            secondry_control_num_25 = 0;
        }
        if(visual_induction_num_24>=visualInductionPointList_24.size()){
            visual_induction_num_24 = 0;
        }
        if(visual_induction_num_25>=visualInductionPointList_25.size()){
            visual_induction_num_25 = 0;
        }
        if(light_control_num_24>=lightControlPointList_24.size()){
            light_control_num_24 = 0;
        }
        if(traffic_control_num_24>=trafficControlPointList_24.size()){
            traffic_control_num_24 = 0;
        }
        if(fan_control_num_24>=fanControlPointList_24.size()){
            fan_control_num_24 = 0;
        }
        // 这个里面是开机运行一次
        if(slectnum==0)
        {
            allServerList = serverService.selectServerformalByInfo( 0, 0,null); // 全部设置为0，获取所有服务列表，只开机获取一次
            slectnum++;
//            redisCache.setCacheObject("CurrentActiveModule", null);
        }
        Map<String, ChannelFuture> connectMap = NettyStarter.getConnectMap(); // 通过netty获取所有连接状态
        if(connectMap.size()==0){
            log.info("无设备连接");
            return;
        }
        else{
            // 获取当前激活模块
            // 筛选出在线的设备
            for(int i = 0; i < allServerList.size(); i++) {
                if(!connectMap.containsKey(allServerList.get(i).getHost() + ":" +allServerList.get(i).getPort())){
                    allServerList.remove(i);
                    i--;
                }
            }
            // 下发读取信息作为心跳保持
            for(ServerEqFormal oneServerEq:allServerList){
                // 先判断模块
                if(oneServerEq.getServer_name_en().startsWith("ip_speaker") || oneServerEq.getServer_name_en().startsWith("ip_board")){
                    continue;
                }
                // 二次事故模块
                if(oneServerEq.getModule_id() == ModuleIdList.SECONDARY_ACCIDENT){
                    FinsMessage finsreadMessage = new FinsMessage();
//                    finsreadMessage = FinsMessageUtils.createReadFineMessage(130, 75, 1, oneServerEq.getHost() + ":" +oneServerEq.getPort(), Constants.DEFAULT_SA1);
//                    ChannelFuture channelFuture = connectMap.get(oneServerEq.getHost()+":"+oneServerEq.getPort());
//                    channelFuture.channel().writeAndFlush(finsreadMessage.toString());
                    String CurrentRequestFinsDevId = "0";
                    // 根据点位信息下发fins指令
                    // 如果是对面山隧道的plc设备
                    if(oneServerEq.getTunnel_id() == TunnelIdList.DUIMIANSHAN_TUNNEL_ID){
                        finsreadMessage = FinsMessageUtils.createReadFineMessage(
                            secondryControlPointList_24.get(secondry_control_num_24).getMemory_area(),
                            (int) secondryControlPointList_24.get(secondry_control_num_24).getRegister_address(),
                            secondryControlPointList_24.get(secondry_control_num_24).getLength(),
                            oneServerEq.getHost() + ":" +oneServerEq.getPort(), Constants.DEFAULT_SA1);

                        CurrentRequestFinsDevId = "fins_plc/"+ secondryControlPointList_24.get(secondry_control_num_24).getTunnel_id()+"/"+
                            secondryControlPointList_24.get(secondry_control_num_24).getModule_id()+"/"+
                            secondryControlPointList_24.get(secondry_control_num_24).getMemory_area()+"/"+
                            secondryControlPointList_24.get(secondry_control_num_24).getRegister_address()+"/"+
                            secondryControlPointList_24.get(secondry_control_num_24).getLength()+"/"+
                            secondryControlPointList_24.get(secondry_control_num_24).getBits();
                    }
                    // 如果是黄陀尖隧道的plc设备
                    else if(oneServerEq.getTunnel_id() == TunnelIdList.HUANGTUOJIAN_TUNNEL_ID){
                        finsreadMessage = FinsMessageUtils.createReadFineMessage(
                            secondryControlPointList_25.get(secondry_control_num_25).getMemory_area(),
                            (int) secondryControlPointList_25.get(secondry_control_num_25).getRegister_address(),
                            secondryControlPointList_25.get(secondry_control_num_25).getLength(),
                            oneServerEq.getHost() + ":" +oneServerEq.getPort(), Constants.DEFAULT_SA1);

                        CurrentRequestFinsDevId = "fins_plc/"+ secondryControlPointList_25.get(secondry_control_num_25).getTunnel_id()+"/"+
                            secondryControlPointList_25.get(secondry_control_num_25).getModule_id()+"/"+
                            secondryControlPointList_25.get(secondry_control_num_25).getMemory_area()+"/"+
                            secondryControlPointList_25.get(secondry_control_num_25).getRegister_address()+"/"+
                            secondryControlPointList_25.get(secondry_control_num_25).getLength()+"/"+
                            secondryControlPointList_25.get(secondry_control_num_25).getBits();
                    }
                    // 记录请求的二次事故管控plc中的哪个设备
                    redisCache.setCacheObject("CurrentRequestSecondryFinsDevId_"+oneServerEq.getTunnel_id(), CurrentRequestFinsDevId);
                    ChannelFuture channelFuture = connectMap.get(oneServerEq.getHost()+":"+oneServerEq.getPort());
                    // 下发指令
                    channelFuture.channel().writeAndFlush(finsreadMessage.toString());
                }
                // 智能消防箱模块
                if(oneServerEq.getModule_id() == ModuleIdList.INTELLIGENT_FIRE_BOX){
                    // 获取连接信息
                    ChannelFuture channelFuture = connectMap.get(oneServerEq.getHost()+":"+oneServerEq.getPort());
                    byte[] inquirecode = new byte[12];
                    for(int a=0;a<5;a++){
                        inquirecode[a] = (byte)0x00;
                    }
                    inquirecode[5] = (byte)0x06;
                    inquirecode[6] = (byte)0x01;
                    inquirecode[7] = (byte)0x03;
                    // 定时读取各个消防箱数据
                    if(fire_box_num<serverPointFormalList.size()){
                        // 长整形转成buye[]
                        byte[] messagebyte = DataUtils.longToBytes(serverPointFormalList.get(fire_box_num).getRegister_address());
                        inquirecode[8] = messagebyte[0];
                        inquirecode[9] = messagebyte[1];
                        inquirecode[10] = (byte)0x00;
                        inquirecode[11] = (byte)serverPointFormalList.get(fire_box_num).getLength();
                        // 发送数据,调用Unpooled.wrappedBuffer方法，将byte[]转成bytebuf发送，不能直接发送byte[]
                        channelFuture.channel().writeAndFlush(Unpooled.wrappedBuffer(inquirecode));
                        String CurrentRequestFireBoxId = "fire_box/"+serverPointFormalList.get(fire_box_num).getMemory_area();
//                        System.out.println(CurrentRequestFireBoxId);
                        redisCache.setCacheObject("CurrentRequestFireBox", CurrentRequestFireBoxId);
                        // 获取当前激活模块
                        String currentactivemodule = redisCache.getCacheObject("CurrentActiveModule");
                        // 处理数据获取报警信息
                        Map<String,String> deviceInfo = new HashMap<String,String>();
                        int fireboxclientnum = serverPointFormalList.get(fire_box_num).getLength()/10;
                        for(int q=0;q<fireboxclientnum;q++){
                            // 获取消防箱的数据
//                            System.out.println(CurrentRequestFireBoxId+"/"+q);
                            String fire_box_data = redisCache.getCacheObject(CurrentRequestFireBoxId+"/"+q);
                            if(fire_box_data!=null){
                                deviceInfo = DataUtils.fireboxdataprocess(fire_box_data);
                                jsonReturn.put("tunnelId","0");
                                if(fire_box_num<=3){
                                    jsonReturn.put("tunnelName","对面山隧道");
                                }
                                else {
                                    jsonReturn.put("tunnelName","黄陀尖隧道");
                                }
                                jsonReturn.put("moduleId","17");
                                jsonReturn.put("clientId",fire_box_num+"分控"+q+"终端");
                                // 若报警标志位不为正常
                                if(!deviceInfo.get("status").equals("正常")){
                                    jsonReturn.put("code", FinsStatus.DEVICE_ALARM);
                                    jsonReturn.put("msg", "消防箱有报警");
                                    jsonReturn.put("operateType", null);
                                    jsonReturn.put("servernameEn", null);
                                    jsonReturn.put("deviceInfo", deviceInfo);
                                    // 根据条件打电话报警
                                    serverPointFormalList.get(fire_box_num).setAlarm_flag("1");
                                    int pushFlag = outboundUtils.alarmPushByConditions(jsonReturn.getString("tunnelName"), jsonReturn.getString("clientId"), deviceInfo, serverPointFormalList.get(fire_box_num));
                                    System.out.println(String.format("pushFlag:%d", pushFlag));
                                    // 如果当前网页连接的是火灾消防模块
                                    if(currentactivemodule.equals(ActiveModule.FIRE_BOX)){
                                        MyChannelHandlerPool.channelGroup.writeAndFlush(new TextWebSocketFrame(JSON.stringify(jsonReturn)));
                                    }
                                }
                            }
                        }
                    }
                }
                // 视觉诱导模块
                if(oneServerEq.getModule_id() == ModuleIdList.VISUAL_INDUCTION){
                    String CurrentRequestFinsDevId = "0";
                    FinsMessage finsreadMessage = new FinsMessage();
                    // 如果是对面山隧道的视觉诱导plc设备
                    if(oneServerEq.getTunnel_id() == TunnelIdList.DUIMIANSHAN_TUNNEL_ID){
                        finsreadMessage = FinsMessageUtils.createReadFineMessage(
                            visualInductionPointList_24.get(visual_induction_num_24).getMemory_area(),
                            (int) visualInductionPointList_24.get(visual_induction_num_24).getRegister_address(),
                            visualInductionPointList_24.get(visual_induction_num_24).getLength(),
                            oneServerEq.getHost() + ":" +oneServerEq.getPort(), Constants.DEFAULT_SA1);

                        CurrentRequestFinsDevId = "fins_plc/"+ visualInductionPointList_24.get(visual_induction_num_24).getTunnel_id()+"/"+
                            visualInductionPointList_24.get(visual_induction_num_24).getModule_id()+"/"+
                            visualInductionPointList_24.get(visual_induction_num_24).getMemory_area()+"/"+
                            visualInductionPointList_24.get(visual_induction_num_24).getRegister_address()+"/"+
                            visualInductionPointList_24.get(visual_induction_num_24).getLength()+"/"+
                            visualInductionPointList_24.get(visual_induction_num_24).getBits();
                    }
                    // 如果是黄陀尖隧道的视觉诱导plc设备
                    else if(oneServerEq.getTunnel_id() == TunnelIdList.HUANGTUOJIAN_TUNNEL_ID){
                        finsreadMessage = FinsMessageUtils.createReadFineMessage(
                            visualInductionPointList_25.get(visual_induction_num_25).getMemory_area(),
                            (int) visualInductionPointList_25.get(visual_induction_num_25).getRegister_address(),
                            visualInductionPointList_25.get(visual_induction_num_25).getLength(),
                            oneServerEq.getHost() + ":" +oneServerEq.getPort(), Constants.DEFAULT_SA1);

                        CurrentRequestFinsDevId = "fins_plc/"+ secondryControlPointList_25.get(visual_induction_num_25).getTunnel_id()+"/"+
                            visualInductionPointList_25.get(visual_induction_num_25).getModule_id()+"/"+
                            visualInductionPointList_25.get(visual_induction_num_25).getMemory_area()+"/"+
                            visualInductionPointList_25.get(visual_induction_num_25).getRegister_address()+"/"+
                            visualInductionPointList_25.get(visual_induction_num_25).getLength()+"/"+
                            visualInductionPointList_25.get(visual_induction_num_25).getBits();
                    }
                    if(finsreadMessage!=null){
                        // 记录请求的二次事故管控plc中的哪个设备
                        redisCache.setCacheObject("CurrentRequestVisualFinsDevId_"+oneServerEq.getTunnel_id(), CurrentRequestFinsDevId);
//                    finsreadMessage = FinsMessageUtils.createReadFineMessage(130, 210, 1, oneServerEq.getHost() + ":" +oneServerEq.getPort(), Constants.DEFAULT_SA1);
                        ChannelFuture channelFuture = connectMap.get(oneServerEq.getHost()+":"+oneServerEq.getPort());
                        // 将数据发送给plc
                        channelFuture.channel().writeAndFlush(finsreadMessage.toString());
                    }
                    else {
                        System.out.println("no visual_induction finsmsg");
                    }
                }
                // 照明控制模块
                if(oneServerEq.getModule_id() == ModuleIdList.LIGHT_CONTROL){
                    String CurrentRequestFinsDevId = "0";
                    FinsMessage finsreadMessage = new FinsMessage();
                    // 如果是对面山隧道的照明控制plc设备
                    if(oneServerEq.getTunnel_id() == TunnelIdList.DUIMIANSHAN_TUNNEL_ID){
                        finsreadMessage = FinsMessageUtils.createReadFineMessage(
                            lightControlPointList_24.get(light_control_num_24).getMemory_area(),
                            (int) lightControlPointList_24.get(light_control_num_24).getRegister_address(),
                            (int) lightControlPointList_24.get(light_control_num_24).getBits(),
                            lightControlPointList_24.get(visual_induction_num_24).getLength(),
                            oneServerEq.getHost() + ":" +oneServerEq.getPort(), Constants.DEFAULT_SA1);

                        CurrentRequestFinsDevId = "fins_plc/"+ lightControlPointList_24.get(light_control_num_24).getTunnel_id()+"/"+
                            lightControlPointList_24.get(light_control_num_24).getModule_id()+"/"+
                            lightControlPointList_24.get(light_control_num_24).getMemory_area()+"/"+
                            lightControlPointList_24.get(light_control_num_24).getRegister_address()+"/"+
                            lightControlPointList_24.get(light_control_num_24).getLength()+"/"+
                            lightControlPointList_24.get(light_control_num_24).getBits();
                    }
                    // 如果是黄陀尖隧道的照明控制plc设备
                    else if(oneServerEq.getTunnel_id() == TunnelIdList.HUANGTUOJIAN_TUNNEL_ID){

                    }
                    if(finsreadMessage!=null){
                        // 记录请求的照明控制plc中的哪个设备
                        redisCache.setCacheObject("CurrentRequestLightControlFinsDevId_"+oneServerEq.getTunnel_id(), CurrentRequestFinsDevId);
//                    finsreadMessage = FinsMessageUtils.createReadFineMessage(130, 210, 1, oneServerEq.getHost() + ":" +oneServerEq.getPort(), Constants.DEFAULT_SA1);
                        ChannelFuture channelFuture = connectMap.get(oneServerEq.getHost()+":"+oneServerEq.getPort());
                        // 将数据发送给plc
                        channelFuture.channel().writeAndFlush(finsreadMessage.toString());
                    }
                    else {
                        System.out.println("no light_control finsmsg");
                    }
                }
                // 交通控制模块
                if(oneServerEq.getModule_id() == ModuleIdList.TRAFFIC_CONTROL){
                    String CurrentRequestFinsDevId = "0";
                    FinsMessage finsreadMessage = new FinsMessage();
                    // 如果是对面山隧道的交通控制plc设备
                    if(oneServerEq.getTunnel_id() == TunnelIdList.DUIMIANSHAN_TUNNEL_ID){
                        finsreadMessage = FinsMessageUtils.createReadFineMessage(
                            trafficControlPointList_24.get(traffic_control_num_24).getMemory_area(),
                            (int) trafficControlPointList_24.get(traffic_control_num_24).getRegister_address(),
                            (int) trafficControlPointList_24.get(traffic_control_num_24).getBits(),
                            trafficControlPointList_24.get(traffic_control_num_24).getLength(),
                            oneServerEq.getHost() + ":" +oneServerEq.getPort(), Constants.DEFAULT_SA1);

                        CurrentRequestFinsDevId = "fins_plc/"+ trafficControlPointList_24.get(traffic_control_num_24).getTunnel_id()+"/"+
                            trafficControlPointList_24.get(traffic_control_num_24).getModule_id()+"/"+
                            trafficControlPointList_24.get(traffic_control_num_24).getMemory_area()+"/"+
                            trafficControlPointList_24.get(traffic_control_num_24).getRegister_address()+"/"+
                            trafficControlPointList_24.get(traffic_control_num_24).getLength()+"/"+
                            trafficControlPointList_24.get(traffic_control_num_24).getBits();
                    }
                    // 如果是黄陀尖隧道的交通控制plc设备
                    else if(oneServerEq.getTunnel_id() == TunnelIdList.HUANGTUOJIAN_TUNNEL_ID){

                    }
                    if(finsreadMessage!=null){
                        // 记录请求的照明控制plc中的哪个设备
                        redisCache.setCacheObject("CurrentRequestTrafficControlFinsDevId_"+oneServerEq.getTunnel_id(), CurrentRequestFinsDevId);
                        ChannelFuture channelFuture = connectMap.get(oneServerEq.getHost()+":"+oneServerEq.getPort());
                        // 将数据发送给plc
                        channelFuture.channel().writeAndFlush(finsreadMessage.toString());
                    }
                    else {
                        System.out.println("no traffic_control finsmsg");
                    }
                }
                // 通风控制模块
                if(oneServerEq.getModule_id() == ModuleIdList.FAN_CONTROL){
                    String CurrentRequestFinsDevId = "0";
                    FinsMessage finsreadMessage = new FinsMessage();
                    // 如果是对面山隧道的通风控制plc设备
                    if(oneServerEq.getTunnel_id() == TunnelIdList.DUIMIANSHAN_TUNNEL_ID){
                        finsreadMessage = FinsMessageUtils.createReadFineMessage(
                            fanControlPointList_24.get(fan_control_num_24).getMemory_area(),
                            (int) fanControlPointList_24.get(fan_control_num_24).getRegister_address(),
                            (int) fanControlPointList_24.get(fan_control_num_24).getBits(),
                            fanControlPointList_24.get(fan_control_num_24).getLength(),
                            oneServerEq.getHost() + ":" +oneServerEq.getPort(), Constants.DEFAULT_SA1);

                        CurrentRequestFinsDevId = "fins_plc/"+ fanControlPointList_24.get(fan_control_num_24).getTunnel_id()+"/"+
                            fanControlPointList_24.get(fan_control_num_24).getModule_id()+"/"+
                            fanControlPointList_24.get(fan_control_num_24).getMemory_area()+"/"+
                            fanControlPointList_24.get(fan_control_num_24).getRegister_address()+"/"+
                            fanControlPointList_24.get(fan_control_num_24).getLength()+"/"+
                            fanControlPointList_24.get(fan_control_num_24).getBits();
                    }
                    // 如果是黄陀尖隧道的通风控制plc设备
                    else if(oneServerEq.getTunnel_id() == TunnelIdList.HUANGTUOJIAN_TUNNEL_ID){

                    }
                    if(finsreadMessage!=null){
                        // 记录请求的照明控制plc中的哪个设备
                        redisCache.setCacheObject("CurrentRequestFanControlFinsDevId_"+oneServerEq.getTunnel_id(), CurrentRequestFinsDevId);
                        ChannelFuture channelFuture = connectMap.get(oneServerEq.getHost()+":"+oneServerEq.getPort());
                        // 将数据发送给plc
                        channelFuture.channel().writeAndFlush(finsreadMessage.toString());
                    }
                    else {
                        System.out.println("no fan_control finsmsg");
                    }
                }
            }
        }
        fire_box_num++;
        secondry_control_num_24++;
        secondry_control_num_25++;
        visual_induction_num_24++;
        visual_induction_num_25++;
        light_control_num_24++;
        traffic_control_num_24++;
        fan_control_num_24++;
    }
}
